package 方格取数;

import java.util.*;

public class Main {
    static int N = 15;
    static int[][][] f = new int[N][N][N];
    static int[][] w = new int[N][N];

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        while (true) {
            int a = in.nextInt();
            int b = in.nextInt();
            int c = in.nextInt();
            if (a == 0 && b == 0 && c == 0) {
                break;
            }
            w[a][b] = c;
        }
        for (int k = 2; k <= 2 * n; k++) {
            for (int i1 = 1; i1 <= n; i1++) {
                for (int i2 = 1; i2 <= n; i2++) {
                    int j1 = k - i1, j2 = k - i2;
                    if (j1 <= 0 || j1 > n || j2 <= 0 || j2 > n) {
                        continue;
                    }
                    int t = w[i1][j1];
                    if (i1 != i2) {
                        t += w[i2][j2];
                    }
                    for (int i = 0; i <= 1; i++) {
                        for (int j = 0; j <= 1; j++) {
                            f[k][i1][i2] = Math.max(f[k][i1][i2], f[k - 1][i1 - i][i2 - j] + t);
                        }
                    }
                }
            }
        }
        System.out.println(f[2 * n][n][n]);
    }
}
